package cn.jimjim.framework.code.generator.common;

/**
 * @author jim
 * @date 2019-04-19
 */
public class BaseResponse<T> {

    private Boolean success;

    private Integer errorCode;

    private String errorMsg;

    private String errorDetail;

    private T data;

    public BaseResponse() {
    }

    public BaseResponse(T data) {
        this.success = Boolean.TRUE;
        this.data = data;
    }

    public BaseResponse(Integer errorCode, String errorMsg, String errorDetail, T data) {
        this.success = Boolean.FALSE;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.errorDetail = errorDetail;
        this.data = data;
    }

    public static <T> BaseResponse<T> success(T data) {
        BaseResponse response = new BaseResponse();
        response.setSuccess(true);
        response.setData(data);
        return response;
    }

    public static BaseResponse failed(Integer errorCode, String errorMsg) {
        return failed(errorCode, errorMsg, errorMsg);
    }

    public static BaseResponse failed(Integer errorCode, String errorMsg, String errorDetail) {
        BaseResponse response = new BaseResponse();
        response.setSuccess(false);
        response.setErrorCode(errorCode);
        response.setErrorMsg(errorMsg);
        response.setErrorDetail(errorDetail);
        return response;
    }

    @Override
    public String toString() {
        return "BaseResponse{" +
                "success=" + success +
                ", errorCode=" + errorCode +
                ", errorMsg='" + errorMsg + '\'' +
                ", errorDetail='" + errorDetail + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
